package com.qupai.controller.user;

import com.qupai.constant.StatusConstant;
import com.qupai.dto.PtRegistrationAddDTO;
import com.qupai.entity.PtActivity;
import com.qupai.result.Result;
import com.qupai.service.PtActivityService;
import com.qupai.service.PtRegistrationService;
import com.qupai.vo.PtActivityVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userPtActivityController")
@RequestMapping("/user/ptactivities")
@Slf4j
@Tag(name = "普通-C端-活动浏览接口")
@RequiredArgsConstructor
public class PtActivityController {
    private final PtActivityService activitiesService;
    private final PtRegistrationService registrationService;


    @GetMapping("/list")
    @Operation(summary = "根据学院分类id查询活动")
    public Result<List<PtActivityVO>>list(Long collegesId){
        PtActivity activities=new PtActivity();
        activities.setCollegesId(collegesId);
        activities.setStatus(StatusConstant.ENABLE);

        List<PtActivityVO> activitiesVOList = activitiesService.list(activities);
        return Result.success(activitiesVOList);
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据id查询活动")
    public Result<PtActivityVO>getById (@PathVariable Long id){
        log.info("根据id查询活动:{}",id);
        PtActivityVO activitiesVO=activitiesService.getById(id);
        return Result.success(activitiesVO);
    }


    @PostMapping
    @Operation(summary = "根据用户id报名活动")
    public Result<String> signUpActivity(@RequestBody PtRegistrationAddDTO registrationAddDTO){
        registrationService.addByStudentId(registrationAddDTO);
        return Result.success();
    }

}
